<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

defined('IN_ADMIN') or die('Hacking Attempt!');

func::isLogin();
mysql::begin(0);

$sTable = 'customer';

//get customerId
$iCustomerId = (isset($_GET['id']) && is_numeric ($_GET['id'])) ? $_GET['id'] : 0;

//update button was clicked
if(!isset($_POST['updateCustomerButton'])){       
        $sSql = 'SELECT * FROM '. $sTable .' WHERE customerId ='. $iCustomerId;
        $aResult = mysql::querySql($sSql);
}else{
     $aVals = array(
        'name' => isset($_POST['name']) ? func::cleanString($_POST['name']) : '',
        'address' => isset($_POST['address']) ? func::cleanString($_POST['address']) : '',
        'homephone' => (isset($_POST['homephone']) && is_numeric($_POST['homephone'])) ? $_POST['homephone'] : 0,
        'cellphone' => (isset($_POST['cellphone']) && is_numeric($_POST['cellphone'])) ? $_POST['cellphone'] : 0,
        'email' => isset($_POST['email']) ? func::cleanEmail($_POST['email']) : '',
        'date' => time()
    );
    $iIdUpdateCustomer = mysql::updateSql($sTable, $aVals, 'customerId', $iCustomerId);

    if($iIdUpdateCustomer){
        func::redirect(func::makeUrl('customer', 'list'));
    }
}
?>
